#include "usbthread.h"

UsbThread::UsbThread(QObject *parent) :
    QThread(parent)
{
    qRegisterMetaType<ProjectStruct>("ProjectStruct");
}

void UsbThread::setDriver(const QString &usbPath)
{
    m_usbPath = usbPath;
}

void UsbThread::setUpdatePath(const QString& usbPath, const QString& backupPath)
{
    m_usbPath = usbPath;
    m_backUpPath = backupPath;
}

//线程运行
void UsbThread::run()
{
    UpdateResource *updateResource = new UpdateResource();

    connect(this, SIGNAL(umountUsb()), updateResource, SLOT(umountUsb()));

    connect(updateResource, SIGNAL(finish()), this, SLOT(quit()));
    connect(updateResource, SIGNAL(startToUpdate(int,QString)), this, SIGNAL(startToUpdate(int,QString)));
    connect(updateResource, SIGNAL(updateFinish(int,ProjectStruct)), this, SIGNAL(updateFinish(int,ProjectStruct)));
    connect(updateResource, SIGNAL(umountUsbState(int)), this, SIGNAL(umountUsbState(int)));

    updateResource->setUpdatePath(m_usbPath, m_backUpPath);
    updateResource->startToUpdate();

    exec();
}
